import { Alova } from '@/utils/http/alova/index';

// 股道信息数据结构
interface TrackInfo {
  createId: string;
  createName: string;
  createTime: string;
  orgArray: string;
  orgArrayName: string;
  orgId: string;
  orgName: string;
  stationId: string;
  trackId: string;
  trackLength: number;
  trackName: string;
  trackType: string;
  updateId: string;
  updateName: string;
  updateTime: string;
  trackTypeName: string;
  coordinatesList: any;
  parkingList: any;
  remark?: string;
}

// 分页查询结果结构
interface PageResult<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
  orders: any[];
  optimizeCountSql: boolean;
  searchCount: boolean;
  countId: string | null;
  maxLimit: string | null;
  pages: number;
}

const baseApi = '/web/proj/track';

/**
 * 获取股道列表
 */
export function getTrackList(params: any) {
  return Alova.Post<InResult<PageResult<TrackInfo>>>(baseApi + '/page', { params });
}

export function getTrackPage(params: any) {
  return Alova.Post<InResult<PageResult<TrackInfo>>>(baseApi + '/page', { params });
}

/**
 * 添加股道
 */
export function addTrack(params: Partial<TrackInfo>) {
  return Alova.Post<InResult<TrackInfo>>(baseApi + '/addRecord', { params });
}

/**
 *  /web/proj/track/byStationId
 * @param params
 * @returns
 */
export function getTracksByStationId(params: any) {
  return Alova.Post<InResult<TrackInfo>>(baseApi + '/byStationId', { params });
}

/**
 * 更新股道信息
 */
export function updateTrack(params: Partial<TrackInfo> & { trackId: string }) {
  return Alova.Post<InResult<TrackInfo>>(baseApi + '/updateRecord', { params });
}

/**
 * 删除股道
 */
export function deleteTrack(params: { trackId: string } | { trackIds: string[] }) {
  return Alova.Post<InResult<boolean>>(baseApi + '/deleteRecord', { params });
}

/**
 * 批量删除股道
 */
export function batchDeleteTracks(trackIds: string[]) {
  return Alova.Post<InResult<boolean>>(baseApi + '/batchDeleteRecords', { trackIds });
}

/**
 * 根据组织ID获取股道列表
 */
export function getTracksByOrgId(params: { orgId: string }) {
  return Alova.Post<InResult<TrackInfo[]>>(baseApi + '/byOrgId', { params });
}
